package com.zt.controller;

import com.zt.anno.LogOperation;
import com.zt.pojo.Dept;
import com.zt.pojo.Result;
import com.zt.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//控制层：接收请求，调用服务，返回结果

@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;

    //查询所有
    @GetMapping
    public Result findAll(){
        List<Dept> deptlist = deptService.findAll();
        return Result.success(deptlist);
    }

    //根据id删除
    @DeleteMapping
    @LogOperation
    public Result deleteById(Integer id){
        deptService.deleteById(id);
        return Result.success();
    }

    //添加员工信息
    @PostMapping
    @LogOperation
    public Result add(@RequestBody Dept dept){
        deptService.add(dept);
        return Result.success();
    }
    //根据id查询
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        Dept dept = deptService.findById(id);
        return Result.success(dept);
    }
    //修改员工信息
    @PutMapping
    @LogOperation
    public Result update(@RequestBody Dept dept){
        deptService.update(dept);
        return Result.success();
    }
}
